<?php

namespace Common\Model;

/**
 * 货币表
 * @modify wenhui 2018-01-30 创建
 */
class CurrencyHotelModel extends BaseModel {
    protected $trueTableName = 'tb_currency_hotel';
    protected $field = 'id,hotelentity_id,currency_id,type,isdelete';

    /**
     * 获取客栈默认货币
     * @modify wenhui 2018-01-30 创建
     * @return array
     */
    public function getDefaultCurrency($hotelIds) {
        if (!is_array($hotelIds)) {
            $hotelIds = implode(',', $hotelIds);
        }

        if (strpos($hotelIds, ',') !== false) {
            $option['hotelentity_id'] = array('in', $hotelIds);
        } else {
            $option['hotelentity_id'] = $hotelIds;
        }

        $option['type'] = 1;
        $data = $this->field($this->field)->where($option)->select();

        return empty($data) ? array() : $data;
    }

    /**
     * 添加条目
     * @modify wenhui 2018-01-30 创建
     * @param  integer   $hotelId    客栈id
     * @param  integer   $currencyId  货币id
     * @param  integer   $type  1=不可删除 0=可删除
     */
    public function addDefaultCurrency($hotelId, $currencyId, $type) {
        $data = array(
            'hotelentity_id' => $hotelId,
            'currency_id' => $currencyId,
            'type' => $type,
        );

        $result = $this->add($data);
        return empty($result) ? false : $result;
    }
}
